package dao;

import java.sql.*;

public class SQLiteConnection {
    private Connection connection = null;

    //连接数据库
    public void Connect_SQLite(){
        try {
            // 加载 SQLite JDBC 驱动程序
            Class.forName("org.sqlite.JDBC");
            // 连接 SQLite 数据库
            String url = "jdbc:sqlite:db/lms.db?journal_mode=WAL;";
            connection = DriverManager.getConnection(url);
            System.out.println("SQLite数据库连接成功！");
        } catch (ClassNotFoundException | SQLException e) {
            System.out.println("SQLi数据库连接失败！");
        }
    }

    //关闭数据库
    public void closeConnection() {
        try {
            if (connection != null && !connection.isClosed()) {
                connection.close();
                System.out.println("SQLite数据库断开连接成功！");
            }
        } catch (SQLException e) {
            System.out.println("SQLite数据库断开连接失败！");
        }
    }

    //获取connection链接信息
    public Connection getConnection() {
        return this.connection;
    }

}

